package com.topfinance.cnaps2.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;

import com.topfinance.cnaps2.dto.ConfOutPortDto;
import com.topfinance.cnaps2.ebo.ConfNodeEbo;
import com.topfinance.cnaps2.ebo.ConfOutPortEbo;
import com.topfinance.cnaps2.ebo.ConfTransportEbo;
import com.topfinance.cnaps2.service.IOutPortManager;
import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.payment.ebo.TCfgNodeEbo;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class OutPortManagerImpl extends HibernateEntityDao<ConfOutPortEbo> implements IOutPortManager {

	private static final Log log = LogFactory.getLog(OutPortManagerImpl.class);

	public void addOutPort(ConfOutPortDto pt) throws AppException{
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,pt.getNID());
		ConfTransportEbo to = (ConfTransportEbo)get(ConfTransportEbo.class,pt.getTID());
		ConfOutPortEbo p = new ConfOutPortEbo();
		BeanUtils.copyProperties(pt, p);
		p.setTransEbo(to);
		p.setNodeEbo(no);
		save(p);
    }
	
	public void editOutPort(ConfOutPortDto pt) throws AppException{
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,pt.getNID());
		ConfTransportEbo to = (ConfTransportEbo)get(ConfTransportEbo.class,pt.getTID());
		ConfOutPortEbo p = new ConfOutPortEbo();
		BeanUtils.copyProperties(pt, p);
		p.setTransEbo(to);
		p.setNodeEbo(no);
		update(p);
    }
	
	//获得传输协议	
	public ConfOutPortEbo getOutPort(Integer uid) throws AppException{
		return (ConfOutPortEbo)get(uid);
	}

	public void deleteOutPort(ConfOutPortDto o) throws AppException{
		removeById(ConfOutPortEbo.class,o.getUid());
    }
	public void deleteOutPort(Integer id) throws AppException{
		removeById(ConfOutPortEbo.class,id);
	}

	//获得传输协议列表
	public List getAllOutPortList() throws AppException{
		String hql = " from ConfOutPortEbo t " ;
		String where = "";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}
}
